package com.yifeng.po;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * Employee(多)----->  Dept
 * @author Administrator
 *
 */
public class User {
    private Long id;            // ID        数据库自动生成
    private String username;    // 员工账号  文本      not null
    private String realName;    // 真实姓名  文本      not null
    private String password;    // 密码      文本      not null
    private String tel;         // 电话      文本      not null
    private String email;       // 邮箱      文本
    private Date inputTime = new Date();     // 录入时间  日期
    private Integer state;      // 状态      数字    0 正常 ，-1离职

    private List<Role> roles = new ArrayList();
    public User() {
    }

    public User(long id) {
        this.id=id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    public Date getInputTime() {
        return inputTime;
    }

//    @DateTimeFormat(pattern = "yyyy-MM-dd")
    public void setInputTime(Date inputTime) {
        this.inputTime = inputTime;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    public List<RoleUser> getRoleEmployee() {
        List<RoleUser> rolesEmployee = new ArrayList<RoleUser>();
        Long employeeId = this.getId();
        List<Role> roles = this.getRoles();
        for (Role role : roles) {
            rolesEmployee.add(new RoleUser(role.getId(), employeeId));
        }
        return rolesEmployee;
    }

    @Override
    public String toString() {
        return "Employee [id=" + id + ", username=" + username + ", realName=" + realName + ", password=" + password
                + "]";
    }
}
